package com.boot.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.business.PurchaseDTO;
import com.boot.feign.ProductFeign;
import com.boot.feign.StorageFeign;
import com.boot.feign.UserFeign;
import com.boot.order.OrderDTO;
import com.boot.order.pojo.Order;
import com.boot.product.vo.ProductVo;
import com.boot.result.Result;
import com.boot.service.OrderService;
import com.boot.mapper.OrderMapper;
import com.boot.user.pojo.User;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.validation.constraints.AssertTrue;
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Objects;
import java.util.UUID;

/**
* @author liyan
* @description 针对表【order】的数据库操作Service实现
* @createDate 2025-05-25 16:15:03
*/
@Service
@AllArgsConstructor
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
    implements OrderService{

    public Result getOrderById(Long id) {
        Order order = baseMapper.selectById(id);
        return Result.success(order);
    }

    @Override
    @Transactional
    public Result createOrder(PurchaseDTO purchaseDTO) {
        Order order = new Order();
        order.setCode(UUID.randomUUID().toString());
        order.setStatus(1);
        order.setProductId(purchaseDTO.getProductId());
        order.setUserId(purchaseDTO.getUserId());
        order.setProductNum(purchaseDTO.getNum());
        order.setTotalAmount(purchaseDTO.getTotalAmount());
        int insertRow = baseMapper.insert(order);
        if (insertRow == 0) {
            return Result.build(500,"创建订单失败",null);
        }
        return Result.success(order);
    }
}




